package com.ymatou.iapi.csim.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.csim.parameter.UpdateLastLastActiveTimeBean;
import com.ymatou.iapi.csim.service.UpdateLastLastActiveTimeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.database.model.ymt_cssession;
import com.ymttest.database.model.ymt_onlinecs;
import com.ymttest.database.sqlwapper.CSIM.ymt_cssessionWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_onlinecsWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
/**
*更新客服最近活动时间
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UpdateLastLastActiveTime{
	private static UpdateLastLastActiveTimeBean bean;
	private static UpdateLastLastActiveTimeCall call;
	private CsimCallService service=new CsimCallService();
	private Integer csId=Integer.parseInt(EnvSetup.getData("csId").toString());
	private Integer userId=Integer.parseInt(EnvSetup.getData("userId_IM").toString());
	private static ymt_onlinecsWapper onlinecsWapper=new ymt_onlinecsWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("更新客服最近活动时间");
	}

	@Before
	public void caseUp() {
		bean=new UpdateLastLastActiveTimeBean();
		call=new UpdateLastLastActiveTimeCall();
		Logger.comment("删除旧数据");
		onlinecsWapper.deleteBy(MapUtil.hashMap("CSId",csId));
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateLastLastActiveTime_1() {
		Logger.start(true,"更新客服最近活动时间-在线");
		try {
			//csIdA上线
			ymt_onlinecs onlinecs=service.getOnlineCS(csId);
			//csIdA 主动会话
			ymt_cssession csSession=service.getOpenSession(csId,userId);
			bean.setCsId(csId);
			call.setData(bean);
			call.callService();			
			//验证
			Logger.verifyEquals("true",DataUtil.Json.parseJsonObj(call.getString("Result")).get("Success").toString(), "验证Success");
			Logger.verifyEquals("200",call.getString("Status"), "验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateLastLastActiveTime_2() {
		Logger.start(true,"更新客服最近活动时间-下线");
		try {
			//csIdA上线
			ymt_onlinecs onlinecs=service.getOnlineCS(csId);
			//csIdA 主动会话
			ymt_cssession csSession=service.getOpenSession(csId,userId);
			//下线
			onlinecs.setStatus(1);
			onlinecsWapper.updateByPrimaryKey(onlinecs);

			bean.setCsId(csId);
			call.setData(bean);
			call.callService();			
			//验证
			Logger.verifyEquals("true",DataUtil.Json.parseJsonObj(call.getString("Result")).get("Success").toString(), "验证Success");
			Logger.verifyEquals("200",call.getString("Status"), "验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateLastLastActiveTime_3() {
		Logger.start(true,"更新客服最近活动时间-下线不存在ymt_onlinecs表中");
		try {
			//csIdA上线
			ymt_onlinecs onlinecs=service.getOnlineCS(csId);
			//csIdA 主动会话
			ymt_cssession csSession=service.getOpenSession(csId,userId);
			//下线
			onlinecs.setStatus(1);
			onlinecsWapper.updateByPrimaryKey(onlinecs);
			onlinecsWapper.deleteBy(MapUtil.hashMap("CSId",csId));
			bean.setCsId(csId);
			call.setData(bean);
			call.callService();			
			//验证
			Logger.verifyEquals("true",DataUtil.Json.parseJsonObj(call.getString("Result")).get("Success").toString(), "验证Success");
			Logger.verifyEquals("200",call.getString("Status"), "验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}